package com.flexdms.i18n;



public class FacesMessage extends javax.faces.application.FacesMessage
{

	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public FacesMessage()
	{
		super();
		setSeverity(SEVERITY_ERROR);
	}

	public FacesMessage(Severity severity, String summary, String detail)
	{
		super(severity, summary, detail);
	}

	public FacesMessage(String summary, Object[] params)
	{
		super(summary);
		this.params=params;
		setSeverity(SEVERITY_ERROR);
	}
	public FacesMessage(String summary, String detail)
	
	{
		super(summary, detail);
		setSeverity(SEVERITY_ERROR);
	}

	public FacesMessage(Exception e)
	{
		if (e instanceof FacesException)
		{
			FacesMessage msgFacesMessage=((FacesException)e).toFacesMessage();
			setDetail(msgFacesMessage.getDetail());
			setSummary(msgFacesMessage.getSummary());
			setSeverity(msgFacesMessage.getSeverity());
			setShouldTranslate(msgFacesMessage.isShouldTranslate());
			setParams(msgFacesMessage.getParams());
			setStaticText(msgFacesMessage.isStaticText());
			setTranslated(msgFacesMessage.isTranslated());
			setTranslateParams(msgFacesMessage.isTranslateParams());
		} else {
			setSummary(e.getMessage());
			setSeverity(SEVERITY_ERROR);
		}
	}

	public FacesMessage(String summary)
	{
		super(summary);
		setSeverity(SEVERITY_ERROR);
	}
	boolean translated=false;
	//text is not dynamic
	boolean staticText=false;
	boolean shouldTranslate=true;
	boolean translateParams=false;
	
	

	public boolean isTranslateParams()
	{
		return translateParams;
	}

	public void setTranslateParams(boolean translateParams)
	{
		this.translateParams = translateParams;
	}

	public boolean isShouldTranslate()
	{
		return shouldTranslate;
	}

	public void setShouldTranslate(boolean shouldTranslate)
	{
		this.shouldTranslate = shouldTranslate;
	}

	public boolean isStaticText()
	{
		return staticText;
	}

	public void setStaticText(boolean staticText)
	{
		this.staticText = staticText;
	}

	public boolean isTranslated()
	{
		return translated;
	}

	public void setTranslated(boolean translated)
	{
		this.translated = translated;
	}
	Object params[];

	public Object[] getParams()
	{
		return params;
	}

	public void setParams(Object params[])
	{
		this.params = params;
	}
	
	
	public static FacesMessage fromFacesMessage(javax.faces.application.FacesMessage msg)
	{
		if (msg instanceof FacesMessage)
		{
			return (FacesMessage) msg;
		}
		FacesMessage fmsgFacesMessage=new FacesMessage(msg.getSeverity(), msg.getSummary(), msg.getDetail());
		return fmsgFacesMessage;
	}
	public static FacesMessage fromException(Exception e)
	{
		if (e instanceof FacesException)
		{
			return ((FacesException)e).toFacesMessage();
			
		} else {
			return new FacesMessage(e);
		}
	}
}
